text .t -yscrollcommand {.s set} -wrap word -width 60 -height 30 -font $font \
-setgrid 1
pack .t -expand y -fill both
# Create a bunch of tags to use in the text widget, such as those for
# section titles and demo descriptions. Also define the bindings for
# tags.
.t tag configure title -font -*-Helvetica-Bold-R-Normal--*-180-*-*-*-*-*-*
.t tag configure demo -lmargin1 1c -lmargin2 1c
if {[winfo depth .] == 1} {
.t tag configure hot -background black -foreground white
} else {
.t tag configure hot -relief raised -borderwidth 1 -background SeaGreen3
}
.t tag bind demo <Button-1> {
invoke [.t index current]
}
set lastLine ""
.t tag bind demo <Enter> {
set lastLine [.t index {@%x,%y linestart}]
.t tag add hot $lastLine "$lastLine lineend"
}
.t tag bind demo <Leave> {
.t tag remove hot 1.0 end
}
.t tag bind demo <Motion> {
set newLine [.t index {@%x,%y linestart}]
if {[string compare $newLine $lastLine] != 0} {
.t tag remove hot 1.0 end
set lastLine $newLine
.t tag add hot $lastLine "$lastLine lineend"
}
}
# Create the text for the text widget.
.t insert end "Tk Widget Demonstrations\n" title
.t insert end {
This application provides a front end for several short scripts that demonstrate what you can do with Tk widgets. Each of the numbered lines below describes a demonstration; you can click on it to invoke the demonstration. Once the demonstration window appears, you can click the "See Code" button to see the Tcl/Tk code that created the demonstration. If you wish, you can edit the code and click the "Rerun Demo" button in the code window to reinvoke the demonstration with the modified code.
}
.t insert end "Labels, buttons, checkbuttons, and radiobuttons\n" title
.t insert end "1. Labels (text and bitmaps).\n" {demo demo-label}
.t insert end "2. Buttons.\n" {demo demo-button}
.t insert end "3. Checkbuttons (select any of a group).\n" {demo demo-check}
.t insert end "4. Radiobuttons (select one of a group).\n" {demo demo-radio}
.t insert end "5. A 15-puzzle game made out of buttons.\n" {demo demo-puzzle}
.t insert end "6. Iconic buttons that use bitmaps.\n" {demo demo-icon}
.t insert end "7. Two labels displaying images.\n" {demo demo-image1}
.t insert end "8. A simple user interface for viewing images.\n" {demo demo-image2}
.t insert end \n {} "Listboxes\n" title
.t insert end "1. 50 states.\n" {demo demo-states}
.t insert end "2. Colors: change the color scheme for the application.\n" \
{demo demo-colors}
.t insert end "3. A collection of famous sayings.\n" {demo demo-sayings}
.t insert end \n {} "Entries\n" title
.t insert end "1. Without scrollbars.\n" {demo demo-entry1}
.t insert end "2. With scrollbars.\n" {demo demo-entry2}
.t insert end "3. Simple Rolodex-like form.\n" {demo demo-form}
.t insert end \n {} "Text\n" title
.t insert end "1. Basic editable text.\n" {demo demo-text}
.t insert end "2. Text display styles.\n" {demo demo-style}
.t insert end "3. Hypertext (tag bindings).\n" {demo demo-bind}
.t insert end "4. A text widget with embedded windows.\n" {demo demo-twind}
.t insert end "5. A search tool built with a text widget.\n" {demo demo-search}
.t insert end \n {} "Canvases\n" title
.t insert end "1. The canvas item types.\n" {demo demo-items}
.t insert end "2. A simple 2-D plot.\n" {demo demo-plot}
.t insert end "3. Text items in canvases.\n" {demo demo-ctext}
.t insert end "4. An editor for arrowheads on canvas lines.\n" {demo demo-arrow}
.t insert end "5. A ruler with adjustable tab stops.\n" {demo demo-ruler}
.t insert end "6. A building floor plan.\n" {demo demo-floor}
.t insert end "7. A simple scrollable canvas.\n" {demo demo-cscroll}
.t insert end \n {} "Scales\n" title
.t insert end "1. Vertical scale.\n" {demo demo-vscale}
.t insert end "2. Horizontal scale.\n" {demo demo-hscale}
.t insert end \n {} "Menus\n" title
.t insert end "1. A window containing several menus and cascades.\n" \
{demo demo-menu}
.t insert end \n {} "Miscellaneous\n" title
.t insert end "1. The built-in bitmaps.\n" {demo demo-bitmap}
.t insert end "2. A dialog box with a local grab.\n" {demo demo-dialog1}
.t insert end "3. A dialog box with a global grab.\n" {demo demo-dialog2}
.t configure -state disabled
# positionWindow --
# This procedure is invoked by most of the demos to position a
# new demo window.
#
# Arguments:
# w - The name of the window to position.
proc positionWindow w {
wm geometry $w +300+300
}
# showVars --
# Displays the values of one or more variables in a window, and
# updates the display whenever any of the variables changes.
#
# Arguments:
# w - Name of new window to create for display.
# args - Any number of names of variables.
proc showVars {w args} {
catch {destroy $w}
toplevel $w
wm title $w "Variable values"
label $w.title -text "Variable values:" -width 20 -anchor center \